# -*- coding: utf-8 -*-
# @Time    : 2022/7/15 15:39
# @Author  : haichuan
# @Email   : 2263126410@163.com
# @File    : tes_zzjg_addbumen_007.py
# @Software: PyCharm

from selenium import webdriver
from selenium.webdriver.common.by import By
from time import  sleep
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support.select import Select


driver=webdriver.Chrome()
driver.maximize_window()

driver.get("http://192.168.12.1/crm/")

action=ActionChains(driver)
# 定位器
'''登录'''
user_name="qq"
user_password="123456"
login_name=(By.NAME,'name')
login_password=(By.NAME,'password')
login_ptn=(By.NAME,'submit')

'''进入组织架构中的添加部门中'''
user_Heads=(By.CSS_SELECTOR,'li.dropdown:nth-child(6) > a:nth-child(1)')
zzjg_xlk=(By.CSS_SELECTOR,'li.dropdown:nth-child(6) > ul:nth-child(2) > li:nth-child(4) > a:nth-child(1)')
zzjg__jgzz=(By.CSS_SELECTOR,'.page-header > h4:nth-child(1) > small:nth-child(1) > a:nth-child(1)')
add_bumen=(By.ID,'add_department')

'''在添加部门弹框中'''
add_bumengname=(By.XPATH,'//*[@id="name"]')
add_bumengnametext='陆地生鲜负责采购部'

add_shangjibumeng=(By.XPATH,'/html/body/div[8]/div[2]/form/div[2]/div/select')
add_bumengtext=(By.XPATH,'/html/body/div[8]/div[2]/form/div[3]/div/textarea')
add_bumengtext_text=("这是一个外出的部门")
add_queren=(By.XPATH,'/html/body/div[8]/div[3]/div/button[1]/span')

# 操作步骤
'''登录'''
driver.find_element(*login_name).send_keys(*user_name)
driver.find_element(*login_password).send_keys(*user_password)
driver.find_element(*login_ptn).click()

'''进入组织架构'''
driver.find_element(*user_Heads).click()
driver.find_element(*zzjg_xlk).click()
driver.find_element(*zzjg__jgzz).click()
driver.find_element(*add_bumen).click()

'''在添加部门弹框中'''
sleep(2)
driver.find_element(*add_bumengname).send_keys(*add_bumengnametext)


xuanze_shangjibumeng=driver.find_element(*add_shangjibumeng)
shangjibumeng_add=Select(xuanze_shangjibumeng)
shangjibumeng_add.select_by_index(1)

driver.find_element(*add_bumengtext).send_keys(add_bumengtext_text)

# driver.find_element(*add_queren).click()


sleep(2)
driver.quit()